package chap2_5;

import java.io.FileInputStream;
import java.io.IOException;

/**
 * @author https://gitee.com/W_Jun
 * @version 1.0
 * @date 2021-11-26 21:27
 * @Description
 */
public class FileInputStreamDemo01 {
    public static void main(String[] args) throws IOException {
        //1.创建字节输入流对象
        FileInputStream fis = new FileInputStream("chapter02-字节流\\fos.txt");

        //2.调用字节输入流对象的读数据方法
        //int read()：从该输入流读取一个字节的数据
/*
        //第一次读取数据
        int by = fis.read();
        System.out.println(by);
        System.out.println((char) by);

        //第二次读取数据
        by = fis.read();
        System.out.println(by);
        System.out.println((char) by);
*/
        //如果达到文件的末尾，read()的返回值是-1
/*        int by = fis.read();
        while (by != -1) {
            System.out.print((char)by);
            by = fis.read();
        }
        System.out.println("============");
*/
        //优化上面的循环
        //fis.read()：读数据
        //by=fis.read()：把读取到的数据赋值给by
        //by != -1：判断读取到的数据是否是-1
        int by;
        while ((by = fis.read()) != -1) {
            System.out.print((char) by);
        }

        //3.释放资源
        fis.close();
    }
}
